package com.hpu.tools;

import com.hpu.bean.Course;

import java.util.List;

/**
 * 课表工具
 * @author Administrator
 *
 */
public class CourseTools {

	public static String[] splitCourse(String course) {
		if (course == null || course.equals(""))
			return null;
		String string1 = "", string2 = "";
		// 对course字符串预处理、切割
		String jsonString = JsonTools.parseJsonString(course);
		String[] courseArray = jsonString.split("#");
		// 遍历
		for (int i = 0; i < courseArray.length; i++) {
			String[] array = courseArray[i].split("&");
			if (array.length <= 10)
				string2 += courseArray[i] + "#";
			else
				string1 += courseArray[i] + "#";
		}
		return new String[] { string1, string2 };
	}

	/**
	 * 将大写的数字转化为整型数值
	 * 
	 * @param string
	 * @return
	 */
	public static int stringToInt(String string) {
		String s = "一二三四五六七八九十";
		int n = -1;
		if ((n = s.indexOf(string)) != -1)
			n = n + 1;
		else if (string.equals("十一"))
			n = 11;
		else if (string.equals("十二"))
			n = 12;
		return n;
	}

	/**
	 * 按照上课节次排序
	 * 
	 * @param data
	 */
	public static void sortList(List<Course>[] data) {
		for (int i = 0; i < data.length; i++)
			for (int m = 0; m < data[i].size() - 1; m++)
				for (int k = m + 1; k < data[i].size(); k++)
					if (data[i].get(m).getStart() > data[i].get(k).getStart()) {
						Course temp = data[i].get(m);
						data[i].set(m, data[i].get(k));
						data[i].set(k, temp);
					}
	}
	
	
	
	/**
	 * 判断该课是否为本周的
	 * @param course
	 * @param cur_week
	 * @return
	 */
	public static boolean isThisWeek(Course course,int cur_week) {
		List<Integer> weekList= course.getWeekList();
		if(weekList.indexOf(cur_week)!=-1) return true;
		return false;
	}
	
}
